<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
</head>
<style>
    .patient_info {
        padding: 0 1rem;
        background-color: #fff;
        margin-bottom: 0.5rem;
        height: 9rem;
    }

    .title {
        padding: 1rem 0;
        font-size: 0.8rem;
        color: #303030;
    }

    .title span {
        float: right;
        color: #2E8EFF;
        font-size: 0.7rem;
    }

    input {
        display: inline-block;
        border-bottom: 1px solid #f3f3f3;
        outline: none;
    }

    .info {
        width: 100%;
        /* height: 2rem; */
        font-size: 0.6rem;
        color: #565656;
        margin: 0rem 0 1rem 0;
    }

    .info div {
        width: 25%;
        display: inline-block;
    }

    .info div:first-child {
        width: 45%;
    }

    .info div input {
        width: 50%;
        text-align: center;
        font-size: 0.6rem;
    }

    .bingming,
    .bingzheng {
        height: 1rem;
        line-height: 1rem;
        margin-bottom: 0.5rem;
        width: 70%;
    }

    .kaifang {
        padding: 0 1rem 0.5rem 1rem;
        background-color: #fff;
        margin-bottom: 0.5rem;
        /* height: 12.5rem; */
    }

    .kaifang .paifang_tip {
        color: #838383;
        font-size: 0.6rem;
        float: right;
        margin-top: 2.75rem;
    }

    .kaifang .paifang_tip img {
        padding-left: 0.3rem;
        width: 0.75rem;
        height: 0.4rem;
    }

    .pharmacy {
        height: 2rem;
        width: 100%;
        position: relative;
        margin-bottom: 1rem;
    }

    .pharmacy .pharmacy_logo {
        width: 2rem;
        height: 2rem;
    }

    .pharmacy .pharmacy_name {
        position: absolute;
        top: 0.2rem;
        left: 2.5rem;
        color: #303030;
        font-size: 0.6rem;
    }

    .pharmacy .subtitle {
        position: absolute;
        bottom: 0.2rem;
        left: 2.5rem;
        color: #838383;
        font-size: 0.5rem;
    }

    .pharmacy .pharmacy_arrow {
        position: absolute;
        width: 0.4rem;
        height: 0.75rem;
        right: 0;
        top: 0.6rem;
    }

    .RP {

        border-top: 1px solid #efefef;

    }

    .RP .add_btn {
        text-align: center;
        width: 11rem;
        height: 2.2rem;
        background-color: #2E8EFF;
        color: #fff;
        font-size: 0.8rem;
        line-height: 2.2rem;
        border-radius: 0.5rem;
        margin: 0 0 0 2rem;
    }

    .RP_main {
        width: 100%;
        background-color: #fff3f3;
    }

    .RP_main .RP_main_item {
        line-height: 3rem;
        color: #565656;
        font-size: 0.7rem;
        width: 33.3%;
        margin-left: -0.25rem;
        display: inline-block;
        text-align: center;
    }

    .useing {
        height: 7rem;
        padding: 0 1rem;
        margin-bottom: 0.5rem;
        background-color: #fff;
    }

    .useing .useing_method {
        height: 1.7rem;
        line-height: 1.7rem;
        border-bottom: 1px solid #ededed;
        color: #565656;
        font-size: 0.6rem;
    }

    .useing .useing_arrow {
        width: 0.4rem;
        height: 0.7rem;
        float: right;
        margin-top: 0.45rem;
    }

    .useing .useing_method span:nth-child(3) {
        margin-right: 0.5rem;
        float: right;
    }

    .useing .useing_detail {
        margin-top: 1rem;
        font-size: 0.6rem;
        color: #565656;
    }

    .useing .useing_detail input {
        width: 15%;
        text-align: center;
    }

    .yizhu {
        padding: 0 1rem;
        background-color: #fff;
        margin-bottom: 0.5rem;
        height: 6rem;
    }

    .yizhu input {
        line-height: 1.7rem;
        width: 100%;
        font-size: 0.6rem;
    }

    .fanganshezhi {
        padding: 0 1rem;
        background-color: #fff;
        margin-bottom: 0.5rem;
    }

    .fanganshezhi .fanganshezhi_item {
        height: 2.1rem;
        border-bottom: 1px solid #f5f5f5;
        line-height: 2rem;
        color: #565656;
        font-size: 0.6rem;
        position: relative;
    }

    .fanganshezhi .fanganshezhi_item .fanganshezhi_arrow {
        position: absolute;
        right: 0;
        width: 0.4rem;
        height: 0.7rem;
        top: 0.85rem;
    }

    .fanganshezhi .fanganshezhi_item .price {
        position: absolute;
        right: 1rem;
        top: 0.25rem;
    }

    .fanganshezhi .fanganshezhi_item .zhenjin {
        position: absolute;
        left: 0;
        top: 0.25rem;
    }

    .fanganshezhi p {
        color: #565656;
        line-height: 1.2rem;
        font-size: 0.5rem;
    }

    .total {
        padding: 0 1rem 1rem 1rem;
        background-color: #fff;
        margin-bottom: 0.5rem;
    }

    .total .item {
        font-size: 0.7rem;
        color: #565656;
        line-height: 1.5rem;
    }

    .total .item span {
        color: #838383;
        float: right;
    }

    .total p {
        color: #565656;
        font-size: 0.5rem;
        margin-top: 0.5rem;
    }

    .total p:first-child {
        font-size: 0.8rem;
    }

    .order_btn {
        width: 90%;
        margin: 2rem 5%;
        height: 2.2rem;
        background-color: #2E8EFF;
        color: #fff;
        font-size: 0.8rem;
        text-align: center;
        border-radius: 0.5rem;
        line-height: 2.2rem;
    }

    .zhezhao_jixing,
    .order_success {
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.7);
        position: fixed;
        left: 0;
        top: 0;
        z-index: 20;
    }

    .zhezhao_jixing .zhezhao_jixing_div {
        position: absolute;
        bottom: 0;
        left: 0;
        height: 20rem;
        width: 100%;
        background-color: #fff;
        border-radius: 0.5rem 0.5rem 0 0;
    }

    .zhezhao_jixing .zhezhao_jixing_div .zhezhao_title {
        height: 2.5rem;
        width: 100%;
        border-bottom: 1px solid #E8E8E8;
        line-height: 2.5rem;
    }

    .zhezhao_jixing .zhezhao_jixing_div .zhezhao_title span:first-child {
        color: #565656;
        font-size: 0.7rem;
        float: left;
        margin-left: 0.8rem;
    }

    .zhezhao_jixing .zhezhao_jixing_div .zhezhao_title span:last-child {
        color: #2780e8;
        font-size: 0.6rem;
        float: right;
        margin-right: 0.8rem;
    }

    .select_catalog {
        width: 2.5rem;
        float: left;
        margin-left: 0.8rem;
        overflow-y: scroll;
        height: 18rem;
    }

    .select_catalog div {
        text-align: center;
        width: 2.5rem;
        background-color: #f9f9f9;
        color: #565656;
        font-size: 0.6rem;
        border-bottom: 1px solid #f3f3f3;
        padding: 0.5rem 0;
    }

    .select_catalog_item {
        float: right;
        margin-right: 0.8rem;
        overflow-y: scroll;
        width: 14rem;
        height: 18rem;
    }

    .select_catalog_item p {
        width: 100%;
        height: 1rem;
        background-color: #F9F9F9;
        font-size: 0.6rem;
        color: #565656;
        line-height: 1rem;

    }

    .select_catalog_item p span {
        margin-left: 0.8rem;
    }

    .select_catalog_item .select_catalog_item_item {
        margin-top: 0.5rem;
        padding: 0.6rem;
        border: 1px solid #E8E8E8;
        border-radius: 0.5rem;
        /* background-color: skyblue; */
        position: relative;
    }

    .select_catalog_item .select_catalog_item_item img {
        width: 3.75rem;
        height: 2.25rem;
    }

    .select_catalog_item .select_catalog_item_item .yaofang_name {
        float: right;
        color: #303030;
        font-size: 0.7rem;
        width: 8rem;
        text-align: left;
        /* background-color: skyblue; */
        margin-top: -0.2rem;
    }

    .select_catalog_item .select_catalog_item_item .yaofang_name span {
        float: right;
        color: #FD6251;
        font-size: 0.6rem;
    }

    .select_catalog_item .select_catalog_item_item .tips {
        width: 8rem;
        /* background-color: skyblue; */
        float: right;
        text-align: left;
        margin: -1.1rem 0 0.4rem 0;
    }

    .select_catalog_item .select_catalog_item_item .tips .tips_item {
        padding: 0.1rem 0.2rem;
        font-size: 0.5rem;
        border: 1px solid #E8E8E8;
        border-radius: 0.2rem;
        display: inline-block;
        margin-right: 0.5rem;
    }

    .select_catalog_item .select_catalog_item_item .tips .tips_item:nth-child(2n) {
        margin-right: 0;
    }

    .select_catalog_item .select_catalog_item_item .price {
        color: #2780e8;
        font-size: 0.6rem;
        bottom: 0.6rem;
        margin-left: 4.7rem;
    }

    .price_zhezhao {
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .price_zhezhao .price_zhezhao_main {
        width: 16.25rem;
        margin-left: 1.25rem;
        margin-top: 7.5rem;
        background-color: #fff;
    }

    .price_zhezhao .price_zhezhao_main .price_title {
        padding: 1rem 0 1rem 1rem;
        color: #565656;
        font-size: 0.8rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div {
        padding: 0 1rem;
        overflow-y: auto;
        height: 11rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div .price_div_item {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div input {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
        outline: none;
        border-bottom: none;
    }

    .price_zhezhao .price_zhezhao_main .btn_div {
        width: 100%;
        height: 3rem;
        line-height: 3rem;
    }

    .price_zhezhao .price_zhezhao_main .btn_div span {
        width: 49%;
        display: inline-block;
        /* margin-left: -0.25rem; */
        text-align: center;
        color: #565656;
        font-size: 0.7rem;
    }

    .order_success_main {
        width: 14rem;
        height: 17.75rem;
        background: url('../image/award_img.png');
        background-size: 100% 100%;
        margin: 7.5rem 0 0 2.5rem;
        text-align: center;
    }

    .order_success_main .order_success_main_title {
        color: #FDDBAF;
        font-size: 1.2rem;
        padding-top: 3rem;

    }

    .order_success_main .order_success_main_subtitle {
        color: #FDDBAF;
        font-size: 0.6rem;
        margin-top: 2rem;
        line-height: 0.75rem;
    }

    .order_success_main .order_success_main_tips {
        color: #FDDBAF;
        font-size: 0.6rem;
        margin-top: 2rem;
    }

    .order_success_main .close_btn {
        font-size: 0.7rem;
        margin: 4rem 0 0 2.9rem;
        text-align: center;
        color: #2780e8;
        background-color: #fff;
        width: 8.2rem;
        height: 2rem;
        line-height: 2rem;
        border-radius: 0.5rem;
    }

    /* ------------------------- */
    .paifang {
        width: 100%;
    }

    .paifang_tips {
        padding: 0.8rem;
        background-color: #fff;
    }

    .paifang_tips .paifang_tips_title {
        color: #303030;
        font-size: 0.7rem;
    }

    .paifang_tips .paifang_tips_other {
        width: 100%;
        margin-top: 0.75rem;
    }

    .paifang_tips .paifang_tips_other p {
        color: #838383;
        font-size: 0.6rem;
        line-height: 1.2rem;
    }

    .paifang_include {
        width: 100%;
        background-color: #fff;
        text-align: center;
    }

    .paifang_include .paifang_include_title {
        color: #838383;
        font-size: 0.6rem;
        padding: 1rem 0;
    }

    .paifang_include .paifang_include_main {
        height: 3.75rem;
        width: 100%;
    }

    .paifang_include .paifang_include_main .paifang_include_main_left {
        width: 3.75rem;
        height: 3.75rem;
        float: left;
    }

    .paifang_include .paifang_include_main .paifang_include_main_right {
        float: right;
        width: 12.5rem;
        height: 100%;
        /* background-color: skyblue; */
        text-align: left;
    }

    .paifang_include .paifang_include_main .paifang_include_main_right .paifang_include_main_right_title {
        color: #838383;
        font-size: 0.5rem;
    }

    .paifang_include .paifang_include_main .paifang_include_main_right .paifang_include_main_right_info {
        color: #565656;
        font-size: 0.6rem;
    }

    .paifang_include .paifang_include_main .paifang_include_main_right p {
        padding-bottom: 0.25rem;
    }

    .paifang_include .paifang_include_main .tips_div {
        color: #838383;
        font-size: 0.6rem;
        float: right;
        margin-top: -0.8rem;
    }

    .paifang_include .paifang_include_main .tips_div img {
        padding-left: 0.3rem;
        width: 0.75rem;
        height: 0.4rem;
    }

    input {
        font-size: 0.6rem;
    }

    .tab_active {
        color: #fff !important;
        background-color: #FD6251 !important;
    }
</style>

<body>
    <div  id="app" v-cloak>
        <div class="placeholder_div"></div>
        <!--  开方 -->
        <div class="kaifang" v-if="kaifang == 0">
            <!-- 患者信息 -->
            <div class="patient_info">
                <p class="title">患者信息
                    <!-- <span class="openwin" data-win="select_hirstory_case_win">调用历史方案</span> -->
                </p>
                <div class="info">
                    <div class="info_name">姓名: <input type="text" v-model="patient_name"></div>
                    <div class="info_sex">性别: <input type="text" v-model="sex_on" readonly onclick="select_sex()"></div>
                    <div class="info_age">年龄: <input type="text" v-model="patient_age"></div>
                </div>
                <input class="bingming" type="text" placeholder="辨病，请填写诊断病名" v-model="bingming">
                <input class="bingzheng" type="text" placeholder="辨证，请填写证候名，选填" v-model="bingzheng">
            </div>
            <!-- 开方 -->
            <div class="kaifang">
                <p class="title">开方</p>

                <div class="pharmacy" @click="zhezhao_jixing = true">
                    <img :src="yaofang_logo" class="pharmacy_logo" alt="">
                    <p class="pharmacy_name" v-if="yaofang_name">{{yaofang_name}}</p>
                    <p class="pharmacy_name" v-else>请选择药房</p>
                    <p class="subtitle">共有{{yaofang_list.length}}家药房可以选择</p>
                    <img class="pharmacy_arrow" src="../image/arrow_right.png" alt="">
                </div>
                <!-- RP -->
                <div class="RP" v-show="yaofang_name" v-if="prescription == ''">
                    <p class="title">RP :</p>
                    <div class="add_btn" onclick="go_add_yaocai_win(0)">添加药材</div>
                </div>

            </div>
            <!-- 药材选择好了 -->
            <div class="RP_main" v-if="prescription" onclick="go_add_yaocai_win(1)">
                <div class="RP_main_item" v-for="item in prescription">{{item}}</div>
            </div>

            <!-- 用法 -->
            <div class="useing">
                <p class="title">用法</p>

                <div class="useing_method" onclick="select_useing_method()">
                    <img class="useing_arrow" src="../image/arrow_right.png" alt="">
                    <span>用药方法</span>
                    <span>{{useing_method_on}}</span>
                </div>

                <div class="useing_detail">
                    <span>共</span><input type="text" v-model="usage_num"><span>帖</span>， <span>每日</span><input
                        type="text" v-model="meiri_tieshu"><span>帖</span>，
                    <span>一帖分</span><input type="text" v-model="cishu"><span>次服用</span>
                </div>
            </div>

            <!-- 医嘱 -->
            <div class="yizhu">
                <p class="title">医嘱</p>
                <input type="text" readonly class="openwin" data-win="yizhu_win" v-model="yizhu_content"
                    :data-content="yizhu_content" placeholder="请填写相关医嘱">
            </div>
            <!-- 方案设置 -->
            <div class="fanganshezhi">
                <p class="title">方案设置</p>
                <div class="fanganshezhi_item" @click="price_zhezhao = true">
                    <span class="zhenjin">诊金</span>
                    <span class="price">￥{{zhenjin_on}}</span>
                    <img class="fanganshezhi_arrow" src="../image/arrow_right.png" alt="">
                </div>

                <div class="fanganshezhi_item" @click="fuwu_price_zhezhao = true">
                    <span class="zhenjin">治疗服务费</span>
                    <span class="price" v-if="service_money == '默认金额'">默认金额</span>
                    <span class="price" v-else>￥{{service_money}}</span>
                    <img class="fanganshezhi_arrow" src="../image/arrow_right.png" alt="">
                </div>

                <div class="fanganshezhi_item" onclick="select_issee()">
                    <span class="zhenjin">购药前处方是否可见</span>
                    <span class="price">{{issee_on}}</span>
                    <img class="fanganshezhi_arrow" src="../image/arrow_right.png" alt="">
                </div>
            </div>

            <!-- 总计 -->
            <div class="total">
                <p class="title">总计 <span>￥{{total_money}}</span></p>
                <div class="item">诊金 <span>￥{{zhenjin_on}}</span></div>
                <div class="item">治疗服务费 <span>￥{{service_money}}</span></div>
                <div class="item">总药价 <span>￥{{drugsPrice}}</span></div>
                <p>*患者不展示治疗服务费，治疗服务费直接计入在药费总额中</p>
                <p>*不含运费、代煎费，药费依据购药时实际选择的药房而定</p>
            </div>

            <!-- 确认选择患者按钮 -->
            <div class="order_btn p_hide" v-if="select_patient == '去选择患者'" @click="select_patient_btn">
                {{select_patient}}</div>
            <div class="order_btn p_hide" v-else @click="queren">{{select_patient}}</div>

        </div>

        <!-- ------------------- 遮罩层 ----------------- -->

        <!-- 遮罩——选择剂型和药房 -->
        <div class="zhezhao_jixing" v-if="zhezhao_jixing">
            <div class="zhezhao_jixing_div">
                <div class="zhezhao_title">
                    <span>选择剂型和药房</span>
                    <span @click="zhezhao_jixing = false">取消</span>
                </div>

                <div class="select_catalog">
                    <!-- <div class="tab_active" @click="select_yaofang(0)" onclick="qieTab(this)">全部
                    </div> -->
                    <div v-for="(item,index) in jixing_list" @click="select_yaofang(item.id,item.name)"
                        onclick="qieTab(this)">
                        {{item.name}}
                    </div>

                </div>

                <div class="select_catalog_item">
                    <!-- <p><span>药费满￥80包邮</span></p> -->

                    <div class="select_catalog_item_item" v-for="item in yaofang_list"
                        @click="yaofang_id = String(item.id),yaofang_name = item.name,yaofang_logo = item.logo,zhezhao_jixing = false">
                        <img :src="item.logo" alt="">
                        <div class="yaofang_name">{{item.name}}
                            <span class="openwin" data-win="pharmacy_detail_win" :data-id="item.id">详情</span>
                        </div>
                        <div class="tips" v-for="items in item.storeSupportVos">
                            <div class="tips_item" v-if="items.keyValue">{{items.keyValue}}</div>
                        </div>
                        <!-- <div class="price">单帖：￥25.3</div> -->

                    </div>
                    <div style="text-align: center;font-size: 0.6rem;margin-top: 1rem;">已经没有更多了~</div>

                </div>
            </div>
        </div>

        <!-- 选择价格遮罩 -->
        <div class="price_zhezhao" v-if="price_zhezhao">
            <div class="price_zhezhao_main">
                <p class="price_title">价格</p>
                <div class="price_div">
                    <p class="price_div_item" v-for="(item,index) in zhenjin" @click="select_zhenjin(item)">
                        ￥{{item}}</p>

                    <input type="number" placeholder="自定义金额(元)" v-model="zidingyi_zhenjin">
                </div>

                <div class="btn_div">
                    <span @click="price_zhezhao = false ">取消</span>
                    <span style="color: #2E8EFF;" @click="zhenjin_queren">确定</span>
                </div>
            </div>
        </div>

        <!-- 成功开单的遮罩 -->
        <div class="order_success" v-if="order_success">
            <div class="order_success_main">
                <p class="order_success_main_title">开出方案成功!</p>
                <p class="order_success_main_subtitle">恭喜您成功开出首张线上方案 <br> 获得3元现金奖励</p>
                <p class="order_success_main_tips">奖励请在【我的收入】中查看</p>

                <div class="close_btn" @click="order_success = false">知道了</div>
            </div>
        </div>

        <!-- 选择治疗服务费价格遮罩 -->
        <div class="price_zhezhao" v-if="fuwu_price_zhezhao">
            <div class="price_zhezhao_main">
                <p class="price_title">治疗服务费价格</p>
                <div class="price_div">
                    <p class="price_div_item" @click="select_fuwu_price('默认金额')" onclick="moren_jine()">
                        默认金额</p>
                    <p class="price_div_item" v-for="(item,index) in serviceMoney"
                        @click="select_fuwu_price(item.servicePrice)">
                        {{item.title}}</p>


                </div>

                <div class="btn_div">
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="../script/set_root.js"></script>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready();

        get_zhenjin()
        if (api.pageParam.index == 1) {
            get_ajax("prescribe/plan/form", {
                id: api.pageParam.fangan_id
            }, function (res, err) {
                if (res.code == 200) {
                    // alert(JSON.stringify(res))
                    for (var i = 0; i < res.data.prescribeDrugs.length; i++) {
                        var items = res.data.prescribeDrugs[i]
                        app.prescription.push(res.data.prescribeDrugs[i].name + res.data.prescribeDrugs[i]
                            .quantity + res.data.prescribeDrugs[i].unit)
                        app.treatmentDrugs.push(items)
                    }
                    // alert(JSON.stringify(app.treatmentDrugs))
                    app.patient_name = res.data.name
                    app.sex = res.data.sex
                    app.patient_age = res.data.age
                    app.bingming = res.data.diseases
                    app.bingzheng = res.data.dialectical
                    app.yaofang_id = res.data.storeId
                    app.yaofang_name = res.data.store
                    app.yaofang_logo = res.data.storeLogo
                    app.dosage_form_id = res.data.dosageFormId
                    app.dosage_form_name = res.data.dosageForm
                    app.useing_method = res.data.usages
                    app.usage_num = res.data.quantity
                    app.meiri_tieshu = res.data.usageNum // 总量多少帖
                    app.cishu = res.data.times // 一贴分多少次服用
                    app.yizhu_content = res.data.medicalAdvice
                    app.visible = res.data.visible
                    app.zhenjin_on = res.data.billingMoney
                    app.service_money = res.data.serviceMoney
                    app.drugsPrice = res.data.drugMoney
                    app.total_money = res.data.totalMoney
                    if (res.data.remark) {
                        app.remark = res.data.remark
                    } else {
                        app.remark = "无"
                    }
                    app.select_patient_name = api.pageParam.name
                    app.select_patient_uid = api.pageParam.id
                    // alert(app.select_patient_uid)
                    app.select_patient = "选择患者并确认"
                } else {
                    alert("网络不通畅，请稍后再试！")
                }
            })
        }

        get_jixing_list() // 获取剂型列表
        // app.select_yaofang(0) // 获取药房列表
        // alert(JSON.stringify($api.getStorage("emp")))

        // 接收win传过来的区分标识
        api.addEventListener({
            name: 'kaifang_tab'
        }, function (ret, err) {
            app.kaifang = ret.value.val
            // alert(ret.value.val)
            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });

        // 接收药材数据
        api.addEventListener({
            name: 'save_yaocai'
        }, function (ret, err) {
            // alert(JSON.stringify(ret.value.total_yaocai));

            app.treatmentDrugs = ret.value.total_yaocai

            app.prescription.length = 0
            for (var i = 0; i < app.treatmentDrugs.length; i++) {
                var item = app.treatmentDrugs[i].name + app.treatmentDrugs[i].quantity + app.treatmentDrugs[
                    i].unit
                app.prescription.push(item)
            }
            if (ret.value.total_yaocai.length == 0) {
                app.prescription = []
            }
        });

        // 接收医嘱页面传出来的医嘱
        api.addEventListener({
            name: 'chuandi_yizhu'
        }, function (ret, err) {
            app.yizhu_content = ret.value.content

            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });

        // // 接受拍方去选择的患者uid，名称
        // api.addEventListener({
        //     name: 'select_patient_on'
        // }, function (ret, err) {
        //     // alert(JSON.stringify(ret.value));
        //     app.select_patient_name = ret.value.name
        //     app.select_patient_uid = ret.value.uid
        //     // app.select_patient = "已选择‘" + ret.value.name + "’，是否确认？"
        //     app.select_patient = "选择患者并确认"
        // });
    }
    //使用vue对数据进行绑定
    var app = new Vue({
        el: '#app',
        data: {
            yaofang_id: "",
            jixing: "", // 选择药房之后展示的剂型
            yaofang_name: "",
            yaofang_logo: "",
            kaifang: 0,
            page: 1,
            paifang_include: false, // 拍方的提示
            zhezhao_jixing: false, // 剂量的遮罩
            price_zhezhao: false, // 诊金的遮罩
            order_success: false, // 开单成功的遮罩
            useing_method_on: "内服", // 用药方法
            useing_method_btns: ["内服", "外用"],
            useing_method: 1, // 用药方法 1=内服 2=外用
            issee_on: "可见",
            issee: ['不可见', '可见'],
            zhenjin_on: 0, // 页面上的诊金
            zhenjin: ['0', '50', '100', '200'],
            zidingyi_zhenjin: "", // 弹出层中的输入框的自定义诊金
            yizhu_content: "", //医嘱内容
            sex: 1,
            sex_on: "男",
            sex_btns: ["男", "女"],
            patient_name: "", // 患者姓名
            patient_age: "", // 患者年龄
            bingming: "", // 病名
            bingzheng: "", // 病症
            dosage_form_id: "0", // 剂型id
            dosage_form_name: "", // 剂型名称
            prescription: [], // 处方药材
            treatmentDrugs: [],
            usage_detail: "", // 用法详述，在created方法中定义
            usage_num: "", // 用量数，默认1
            meiri_tieshu: "", // 每日多少帖
            cishu: "", // 一帖多少次
            visible: 1, // 购药前处方是否可见  1可见  0不可见
            serviceMoney: [], // 服务费数组
            service_money: "默认金额", // 服务费
            drug_money: "100", // 药价
            status: "0", // 0 待购药  1 已购药
            remark: "", //备注
            drugsPrice: 0, // 药材总价格
            jixing_list: [], // 剂型列表
            yaofang_list: [], // 药房列表
            headimg: "../image/updata_img.png", // 拍方的照片
            select_patient: "去选择患者", // 去选择患者按钮
            select_patient_name: "", // 拍方选择的患者名称
            select_patient_uid: "", // 拍方选择的患者uid
            total_money: 0, // 全部价格
            fuwu_price_zhezhao: false, // 服务费选择遮罩
        },
        methods: {
            // 选择药房
            select_yaofang: function (id, name) {
                get_ajax("store/listPageByDosageId", {
                    start: app.page,
                    pagesize: 10,
                    dosageId: String(id),
                }, function (res, err) {
                    // alert(JSON.stringify(res.data.data))
                    if (res.code == 200) {
                        app.yaofang_list = res.data.data
                        app.dosage_form_id = id
                        app.dosage_form_name = name
                        app.$nextTick(function () {
                            hb_init_openwinby_click();
                        })
                    } else {
                        toast("网络不通畅，请稍后再试！")
                    }
                    if (err) {
                        alert("网络不通畅，请稍后再试！")
                    }
                })
            },
            // 遮罩层中选择诊金
            select_zhenjin: function (price) {
                this.zhenjin_on = price
                this.price_zhezhao = false

                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            // 遮罩层中选择服务费
            select_fuwu_price: function (price) {
                // alert(price)
                this.service_money = price
                this.fuwu_price_zhezhao = false

                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            zhenjin_queren: function () {
                if (this.zidingyi_zhenjin) {
                    this.zhenjin_on = this.zidingyi_zhenjin
                    this.price_zhezhao = false

                    app.$nextTick(function () {
                        hb_init_openwinby_click();
                    })
                } else {
                    toast("请选择或输入诊金价格")
                }
            },
            // 确认新增开方
            queren: function () {
                if (this.patient_name == "") {
                    toast("请输入患者姓名")
                } else if (this.patient_age == "") {
                    toast("请输入患者年龄")
                } else if (this.bingming == "") {
                    toast("请输入病名")
                } else if (this.bingzheng == "") {
                    toast("请输入病症")
                } else if (this.yaofang_id == "") {
                    toast("请输入药房id")
                } else if (this.yaofang_name == "") {
                    toast("请输入药房名称")
                } else if (this.yaofang_logo == "") {
                    toast("请输入药房logo")
                } else if (this.prescription == "") {
                    toast("请输入处方药材")
                } else if (this.usage_detail == "") {
                    toast("请输入用法详述")
                } else if (this.usage_num == "") {
                    toast("请输入用量数")
                } else if (this.meiri_tieshu == "") {
                    toast("请输入每日使用多少帖")
                } else if (this.cishu == "") {
                    toast("请输入每一帖使用多少次数")
                } else if (this.yizhu_content == "") {
                    toast("请输入相关医嘱")
                } else if (this.drug_money == "") {
                    toast("请输入药价")
                } else {
                    post_ajax("prescribe/plan/save", {
                        doctorId: Number($api.getStorage("emp").userId), // 医生账号id
                        doctor: $api.getStorage("emp").realname, // 医生姓名
                        // doctor: "测试",
                        userId: Number(app.select_patient_uid), // 选择的患者id
                        name: String(app.patient_name), // 患者姓名
                        sex: Number(app.sex), // 患者性别
                        age: Number(app.patient_age), // 患者年龄
                        diseases: String(app.bingming), // 病名
                        dialectical: String(app.bingzheng), // 病症
                        storeId: Number(app.yaofang_id), // 药房id
                        store: String(app.yaofang_name), // 药房名称
                        source: "online",
                        storeLogo: String(app.yaofang_logo), // 药房logo
                        dosageFormId: String(app.dosage_form_id), // 剂型id
                        dosageForm: String(app.dosage_form_name),
                        prescription: String(app.prescription), // 处方药材
                        usage: Number(app.useing_method), //用药方法
                        quantity: Number(app.usage_num), // 总量多少帖
                        usageNum: Number(app.meiri_tieshu), // 每日多少帖
                        times: Number(app.cishu), // 一贴分多少次服用
                        usageDetail: String(app.usage_detail), // 用法详述
                        medicalAdvice: String(app.yizhu_content), //医嘱
                        visible: Number(app.visible), // 购药前处方是否可见
                        billingMoney: Number(app.zhenjin_on), // 诊费诊金
                        serviceMoney: Number(app.service_money), // 服务费
                        drugMoney: Number(app.drug_money), // 药价
                        totalMoney: Number(app.total_money), // 合计金额
                        // status: String(app.status), // 待购药
                        remark: String(app.remark), // 备注
                        prescribeDrugs: app.treatmentDrugs, // 处方药材
                    }, function (res, err) {
                        // alert(JSON.stringify(res))
                        if (res.data) {
                            get_ajax("prescribe/plan/im-message", {
                                id: res.data
                            }, function (result, error) {
                                if (result.code == 200) {
                                    // alert(JSON.stringify(result))
                                    send_msg(JSON.stringify(result.data))
                                    // var regex3 = /\{(.+?)\}/g;
                                    // alert(String(JSON.stringify(result.data)).match(regex3))
                                } else {
                                    alert(JSON.stringify(error))
                                }

                            })

                            // this.order_success = true
                            // toast(res.msg)
                            // setTimeout(function () {
                            //     api.closeWin()
                            // }, 500);


                            app.$nextTick(function () {
                                hb_init_openwinby_click();
                            })
                        } else {
                            // toast("网络不通畅，请稍后再试！")
                            alert(JSON.stringify(res))
                            alert(JSON.stringify(err))
                        }
                    })
                }
            },
            select_patient_btn: function () {
                api.openWin({
                    name: "my_patient_win",
                    url: "my_patient_win.html",
                    pageParam: {
                        select_patient: true
                    }
                })
            },
        },
        watch: {
            zhezhao_jixing: function (val) {
                if (val) {
                    $("body").css('overflow', 'hidden')
                } else {
                    $("body").css('overflow', 'visible');
                }

                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            price_zhezhao: function (val) {
                if (val) {
                    $("body").css('overflow', 'hidden')
                } else {
                    $("body").css('overflow', 'visible')
                }

                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            order_success: function (val) {
                if (val) {
                    $("body").css('overflow', 'hidden')
                } else {
                    $("body").css('overflow', 'visible')
                }

                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            zhenjin_on: function (val) {
                this.total_money = Number(this.zhenjin_on) + Number(this.service_money) + Number(this
                    .drugsPrice)
            },
            service_money: function (val) {
                this.total_money = Number(this.zhenjin_on) + Number(this.service_money) + Number(this
                    .drugsPrice)
            },
            drugsPrice: function (val) {
                this.total_money = Number(this.zhenjin_on) + Number(this.service_money) + Number(this
                    .drugsPrice)
            },
        },
        created: function () {
            this.usage_detail = "共" + this.usage_num + "帖，每日" + this.meiri_tieshu + "帖，一贴分" + this.cishu +
                "次服用" // 定义用法详述
        },
    })

    // 选择性别
    function select_sex() {
        api.actionSheet({
            title: '请选择患者性别',
            cancelTitle: '取消',
            buttons: app.sex_btns
        }, function (ret, err) {
            var index = ret.buttonIndex; //下标从1开始
            if (index == 3) {
                return
            }
            app.sex = index;
            for (var i = 0; i < app.sex_btns.length; i++) {
                if (index - 1 == i) {
                    app.sex_on = app.sex_btns[i]
                }
            }
            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });
    }

    // 选择用药方法
    function select_useing_method() {
        api.actionSheet({
            title: '选择用药方法',
            cancelTitle: '取消',
            buttons: app.useing_method_btns
        }, function (ret, err) {
            var index = ret.buttonIndex; //下标从1开始
            if (index == 3) {
                return
            }
            app.useing_method = index
            for (var i = 0; i < app.useing_method_btns.length; i++) {
                if (index - 1 == i) {
                    app.useing_method_on = app.useing_method_btns[i]
                }
            }
            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });
    }

    // 选择是否可见
    function select_issee() {
        api.actionSheet({
            title: '请选择是否可见',
            cancelTitle: '取消',
            buttons: app.issee
        }, function (ret, err) {
            var index = ret.buttonIndex; //下标从1开始
            if (index == 3) {
                return
            }
            app.visible = index - 1
            for (var i = 0; i < app.issee.length; i++) {
                if (index - 1 == i) {
                    app.issee_on = app.issee[i]
                }
            }
            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });
    }

    // 获取剂型列表
    function get_jixing_list() {
        get_ajax("item/dosageform/list", {}, function (res, err) {
            if (res.code == 200) {
                app.jixing_list = res.data
            } else {
                toast("网络不通畅，请稍后再试！")
            }
            if (err) {
                alert("网络不通畅，请稍后再试！")
            }
        })
    }

    // 剂型的切换
    function qieTab(obj) {
        $('.tab_active').removeClass('tab_active');
        $(obj).addClass('tab_active')
    }

    // 去到添加药材
    function go_add_yaocai_win(index) {
        api.openWin({
            name: "add_yaocai_win",
            url: "add_yaocai_win.html",
            pageParam: {
                id: app.yaofang_id,
                title: app.yaofang_name,
                total_yaocai: app.treatmentDrugs,
                index: index,
            }
        })
    }

    // 发送消息
    function send_msg(msg) {
        var identifier = $api.getStorage("emp").userId
        var side_identifier = app.select_patient_uid
        var tencentIm = api.require('tencentIm');
        tencentIm.init({appid:"1400407726"}, function (ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                get_ajax("im/getUserSig", {
                    identifier: identifier
                }, function (res, err) {
                    tencentIm.login({
                        identifier: identifier,
                        userSig: res.data,
                    }, function (ret, err) {
                        if (ret) {
                            // alert(JSON.stringify(ret));

                            tencentIm.getConversation({
                                peer: side_identifier,
                                type: 1,
                            }, function (ret, err) {
                                if (ret) {
                                    tencentIm.sendText({
                                        peer: side_identifier,
                                        type: 1,
                                        text: msg,
                                    }, function (ret, err) {
                                        if (ret) {
                                            // alert(JSON.stringify(ret));
                                            // alert(JSON.stringify(msg))
                                            alert("开方成功,请等待药房划价后前往拍方记录查看!")
                                            api.closeWin()
                                        } else {
                                            alert("网络不通畅，请稍后再试！");
                                        }
                                    });
                                }
                            })

                        } else {
                            alert("网络不通畅，请稍后再试！");
                        }
                    });
                })

            } else {
                alert("网络不通畅，请稍后再试！");
            }
        });
    }

    function get_zhenjin() {
        get_ajax("doctor/service-price", {
            doctorUserId: $api.getStorage("emp").userId
        }, function (res, err) {
            if (res) {
                // alert(JSON.stringify(res))
                app.serviceMoney = res.data
            } else {
                alert("网络不通畅，请稍后再试！")
            }
        })
    }

    function moren_jine() {
        get_ajax("doctor/default-service-price", {
            doctorUserId: $api.getStorage("emp").userId,
            drugsPrice: String(app.drugsPrice)
        }, function (res, err) {
            if (res.code == 200) {
                // alert(JSON.stringify(res))
                app.service_money = res.data
            } else {
                alert("网络不通畅，请稍后再试！")
            }
        })
    }
</script>
